/*
 * This file is part of aion-unique <aion-unique.com>.
 *
 *     Aion-unique is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Aion-unique is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionemu.gameserver.network.aion.serverpackets;

import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.model.gameobjects.player.TitleList;
import com.aionemu.gameserver.model.gameobjects.player.TitleListEntry;
import com.aionemu.gameserver.network.aion.AbstractAionServerPacket;
import com.aionemu.gameserver.network.aion.GameClient;

/**
 * 
 * @author Lyahim, Nemiroff
 * @author Lyahim, M@xx Date: 01.12.2009
 * 
 */
public class SM_TITLE_LIST extends AbstractAionServerPacket<GameClient>
{
	private TitleList	titleList;
	private int titleId;
	private int objectId;
	private int action;

	public SM_TITLE_LIST(Player player)
	{
		this.action = 0;
		this.titleList = player.getTitleList();
	}

	public SM_TITLE_LIST(int titleId)
	{
		this.action = 1;
		this.titleId = titleId;
	}

	public SM_TITLE_LIST(int objectId, int titleId)
	{
		this.action = 2;
		this.titleId = titleId;
		this.objectId = objectId;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void writeImpl(GameClient client)
	{
		switch (action)
		{
			//list
			case 0:
				writeH(0x00);
				writeH(titleList.size());
				for (TitleListEntry title : titleList.getTitles())
				{
					writeD(title.getId());
					writeD(title.getRemainingTime());
				}
				break;
				//set title
			case 1:
				writeC(1);
				writeD(titleId);
				break;
				//update brodcast
			case 2:
				writeD(objectId);
				writeD(titleId);
				break;
		}
	}
}
